package code._19container._03map;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.*;

public class Ex2 {
    public static void main(String[] args) {
        HashMap<Level, List<Student>> map = new HashMap<>();
        List<Student> students = generateStudents();
        for (Student student : students) {
            double score = student.getScore();
            Level level=getScoreLevel(score);
            List<Student> listStudent = map.getOrDefault(level, new ArrayList<Student>());
            listStudent.add(student);
            map.put(level,listStudent);
        }
        map.forEach((key,value)-> System.out.println(key+": "+value));
    }

    private static Level getScoreLevel(double score) {
        if(score>80){
            return Level.EXCELLENT;
        }else if (score>60){
            return Level.GOOD;
        }else {
            return Level.BAD;
        }
    }

    //初始化
    public static List<Student> generateStudents() {
        List<Student> students = new ArrayList<>();
        Random random = new Random();
        List<String> provinceList = Arrays.asList("湖北省", "广东省", "河南省");
        for (int i = 0; i < 50; i++) {
            Student student = new Student();
            student.setName("student-" + i);
            String province = provinceList.get(i % 3);
            student.setPrivince(province);
            int i1 = random.nextInt(101);
            student.setScore(i1);
            // 添加到容器中
            students.add(student);
        }
        return students;
    }
}



@Data
@NoArgsConstructor
@AllArgsConstructor
class Student{
    String privince;
    String name;
    double score;
}

enum Level{
    BAD,
    GOOD,
    EXCELLENT
}
